#ifndef   _SYS_PARAM_H_
#define   _SYS_PARAM_H_

#include "ddl.h"
#include "adc.h"
#include "gpio.h"


typedef enum{
  // 
  NO_ERR = 0,
  HOST_UNCHARGE_BASE_INCHARGE = 1,  // 200秒闪灭
  HOST_INCHARGE_BASE_UACHARGE,      // 500秒闪灭

}SY_ERR_e;


typedef enum{
    IDLE_STA = 1,
    CHARING_FIRST_1MIN_STA,
    CHARING_STA,
    CHARGED_FINISH_STA,
    CHARGE_ERR_STA,
    ALING_CHARGE_STA,     // 老化模式下 充电
    ALING_DIS_CHARGE_STA, // 老化模式下，非充电 
}STATE_e;

typedef enum{
  ADC_CHECK_OFFLINE = 1,
  ADC_CHECK_CHARGINE,
  ADC_CHARG_FINISH,

}ADC_CHECK_STA_e;


typedef enum{
    ALING_MODE_CHARG_STA = 0, // 老化模式下充电装态
    ALING_MODE_OUTPUT_STA,    // 老化模式下输出状态，此时暂停充电

}ALING_MOSDE_STA_e;

typedef enum{
    BAT_STA_CMD = 0x04, // 老化模式下充电装态
    ALING_STA_CMD = 0x0f,  // 老化状态

}UART_CMD_e;


typedef enum{
   BAT_VOLTAGE_REQ = 1,
   BAT_VOLTAGE_ACK,
   CHARGE_STA_REQ,
   CHARGE_STA_ACK,
}BAT_CMD_e;




typedef enum{
   BAT_UNKNOWN = 0, // 没有识别到
   
   BAT_CHARGING,
   BAT_CHARGE_FINISH,
}BAT_CHARGE_STA_e;

// 最大通讯超时时间
#define MAX_HOST_UNACK_CNT  100

// 充电使能关闭延时
#define CHARGE_EN_DELAY     600 // 延时10min后关闭

typedef struct 
{
    /* data */
    int sys_5ms_flag;
    int sys_10ms_flag;
    int sys_1s_flag;
    int charge_cnt;
		int run_cnt;
    int close_charge_en_delay;  // 关闭充电使能

    uint8_t recv_host_msg_flag;
    uint8_t host_charging_flag;
    uint8_t host_charg_full_flag;
    uint8_t rcv_charge_full_cnt;

    uint8_t host_offline_cnt;  // 主机离线
    uint8_t host_online_cnt;
    uint8_t host_online_flag;
    uint8_t force_dischage_cnt;  // 强制不充电 计时

    ADC_CHECK_STA_e base_adc_sta;
   

    STATE_e sta;
    STATE_e last_sta;


}SYS_PARAM_t;



extern SYS_PARAM_t sys_data;

void set_sys_sta(STATE_e new_sta);
STATE_e get_sys_sta(void);
void sys_param_init(void);


#endif